// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

package net.minecraft.src;

import java.util.List;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;

// Referenced classes of package net.minecraft.src:
//            PropsMod, Achievement, PlayerControllerSP, PlayerControllerMP, 
//            ScaledResolution, ModLoader, GameSettings, KeyBinding, 
//            Item, EntityPlayer, Entity, AxisAlignedBB, 
//            World, WorldInfo, FontRenderer, MathHelper, 
//            Props303, GuiScreen

public class mod_MovePlus extends BaseMod
    implements Runnable
{

    public void run()
    {
        try
        {
            while(true) 
            {
                mod_MovePlus mod_moveplus = this;
                if(mc == null)
                {
                    mod_MovePlus mod_moveplus1 = this;
                    mc = ModLoader.getMinecraftInstance();
                }
                mod_MovePlus mod_moveplus2 = this;
                if(mc == null)
                {
                    Thread.sleep(5000L);
                } else
                {
                    mod_MovePlus mod_moveplus3 = this;
                    if(mc.thePlayer == null)
                    {
                        Thread.sleep(5000L);
                    } else
                    {
                        mod_MovePlus mod_moveplus4 = this;
                        worldRef = mc.theWorld;
                        mod_MovePlus mod_moveplus5 = this;
                        theplayer = mc.thePlayer;
                        keys = (new int[] {
                            mc.gameSettings.keyBindForward.keyCode, mc.gameSettings.keyBindLeft.keyCode, mc.gameSettings.keyBindBack.keyCode, mc.gameSettings.keyBindRight.keyCode, mc.gameSettings.keyBindJump.keyCode
                        });
                        Thread.sleep(10000L);
                    }
                }
            }
        }
        catch(Throwable throwable)
        {
            throwable.printStackTrace();
        }
    }

    public mod_MovePlus()
    {
        ModLoader.SetInGameHook(this, true, false);
        ModLoader.SetInGUIHook(this, true, false);
        theplayer = null;
        (new Thread(this)).start();
        boostdodged = (new Achievement(456, "boostdodged", 0, 0, Item.feather, null)).registerAchievement();
        ModLoader.AddAchievementDesc(boostdodged, "Boost Dodge", "Perform a Boost Dodge.");
    }

    public static void displayMessage(String s, int i)
    {
        msg = s;
        timeout = 85;
        color = i;
    }

    public static void displayMessage(String s)
    {
        displayMessage(s, defaultColor);
    }

    public static void checkKey(int i)
    {
        if(useSpeedJump && i == 4 && Keyboard.isKeyDown(keys[i]) && !speedJumped && tickCount - landTime < 3L)
        {
            double d = theplayer.motionY;
            double d1 = Math.sqrt(theplayer.motionX * theplayer.motionX + theplayer.motionZ * theplayer.motionZ);
            if(d1 < (double)speedJumpMax)
            {
                performMove(keys[i], false, false, true);
            }
            theplayer.motionY = d;
            speedJumped = true;
            keyTimes[i] = tickCount - 500L;
        }
        if(useDoubleJump && i == 4 && secondPress[i] && Keyboard.isKeyDown(keys[i]))
        {
            if(!theplayer.onGround && !doubleJumped)
            {
                if(!doubleJumped)
                {
                    performMove(keys[i], false, false);
                }
                doubleJumped = true;
            }
            secondPress[i] = false;
            keyTimes[i] = tickCount - 500L;
        }
        if(tickCount - keyTimes[i] < (long)dodgeMinDelayTime && secondPress[i] && Keyboard.isKeyDown(keys[i]))
        {
            if(useBoostDodge && Keyboard.isKeyDown(Keyboard.getKeyIndex("SPACE")) && keyTimes[i] - keyTimes[4] - 500L < 5L && nearWall(theplayer))
            {
                theplayer.triggerAchievement(boostdodged);
                performMove(keys[i], true, false);
            } else
            if(useWallDodge && (theplayer.onGround || nearWall(theplayer)))
            {
                performMove(keys[i], false, false);
            } else
            if(useGroundDodge && !dodged && !doubleJumped)
            {
                performMove(keys[i], false, true);
            }
            dodged = true;
            secondPress[i] = false;
            keyTimes[i] = tickCount - 500L;
        }
        if(!Keyboard.isKeyDown(keys[i]) && !secondPress[i])
        {
            secondPress[i] = true;
        }
        if(Keyboard.isKeyDown(keys[i]) && secondPress[i])
        {
            secondPress[i] = false;
            lastKey = keys[i];
            keyTimes[i] = tickCount;
        }
    }

    public static boolean nearWall(Entity entity)
    {
        return entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox.expand(0.20000000000000001D, 0.0D, 0.20000000000000001D)).size() > 0;
    }

    public void OnTickInGame(Minecraft minecraft)
    {
        if(!ingui)
        {
            OSDHook(minecraft, false);
        }
        ingui = false;
    }

    public void OnTickInGUI(Minecraft minecraft, GuiScreen guiscreen)
    {
        ingui = true;
    }

    public static void airControl(Entity entity)
    {
        if(useAirControl && timeCount != worldRef.worldInfo.getWorldTime())
        {
            float f = 0.0F;
            float f1 = 0.0F;
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindForward.keyCode))
            {
                f++;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindLeft.keyCode))
            {
                f1--;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindBack.keyCode))
            {
                f--;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindRight.keyCode))
            {
                f1++;
            }
            double d = Math.sqrt(entity.motionX * entity.motionX + entity.motionZ * entity.motionZ);
            if(dolphinSkills && theplayer.isInWater())
            {
                if(d < (double)dolphinSpeedMax && d > 0.0099999997764825821D && (f != 0.0F || f1 != 0.0F))
                {
                    setRelVel2(theplayer, f1, (float)entity.motionY, f, dolphinSpeed);
                }
            } else
            if(useAirControl && !theplayer.onGround && d < (double)airControlSpeedMax && d > 0.0099999997764825821D && (f != 0.0F || f1 != 0.0F))
            {
                setRelVel(theplayer, f1, (float)entity.motionY, f, airControlSpeed);
            }
        }
    }

    public void OSDHook(Minecraft minecraft, boolean flag)
    {
        if(theplayer != null && !flag && (!worldRef.multiplayerWorld || superMagicProperty))
        {
            boolean flag1 = nearWall(theplayer);
            for(int i = 0; i < keys.length; i++)
            {
                checkKey(i);
            }
            

            if(!theplayer.onGround || theplayer.isInWater())
            {
                airControl(theplayer);
            }
            if(theplayer.motionY > -1D)
            {
                theplayer.fallDistance = 0.0F;
            }
            if(theplayer.onGround)
            {
                speedJumped = false;
                doubleJumped = false;
                dodged = false;
                if(!lastTickLanded)
                {
                    lastTickLanded = true;
                    landTime = tickCount;
                }
            } else
            {
                lastTickLanded = false;
            }
            prevTimeCount = timeCount;
            timeCount = worldRef.worldInfo.getWorldTime();
            if(timeCount > prevTimeCount)
            {
                tickCount += timeCount - prevTimeCount;
            }
            if(speedMining)
            {
                if(!worldRef.multiplayerWorld)
                {
                    try
                    {
                        Object obj = ModLoader.getPrivateValue(net.minecraft.src.PlayerControllerSP.class, (PlayerControllerSP)ModLoader.getMinecraftInstance().playerController, "f");
                        float f = Float.valueOf(obj.toString()).floatValue();
                        if(f > 0.01F)
                        {
                            f += 0.05F;
                            if(f > 1.0F)
                            {
                                f = 1.0F;
                            }
                            ModLoader.setPrivateValue(net.minecraft.src.PlayerControllerSP.class, (PlayerControllerSP)ModLoader.getMinecraftInstance().playerController, "f", Float.valueOf(f));
                        }
                        ModLoader.setPrivateValue(net.minecraft.src.PlayerControllerSP.class, (PlayerControllerSP)ModLoader.getMinecraftInstance().playerController, "i", Integer.valueOf(0));
                    }
                    catch(Exception exception) { }
                } else
                if(superMagicProperty)
                {
                    try
                    {
                        /*Object obj1 = ModLoader.getPrivateValue(net.minecraft.src.PlayerControllerMP.class, (PlayerControllerMP)ModLoader.getMinecraftInstance().playerController, "f");
                        float f1 = Float.valueOf(obj1.toString()).floatValue();
                        if(f1 > 0.01F)
                        {
                            f1 += 0.05F;
                            if(f1 > 1.0F)
                            {
                                f1 = 1.0F;
                            }
                            ModLoader.setPrivateValue(net.minecraft.src.PlayerControllerMP.class, (PlayerControllerMP)ModLoader.getMinecraftInstance().playerController, "f", Float.valueOf(f1));
                        }*/
                        ModLoader.setPrivateValue(net.minecraft.src.PlayerControllerMP.class, (PlayerControllerMP)ModLoader.getMinecraftInstance().playerController, "i", Integer.valueOf(0));
                    }
                    catch(Exception exception1) { }
                }
            }
        }
        if(timeout > 0 && msg != null)
        {
            ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
            int j = scaledresolution.getScaledWidth();
            int k = scaledresolution.getScaledHeight();
            int l = minecraft.fontRenderer.getStringWidth(msg);
            minecraft.fontRenderer.drawStringWithShadow(msg, 3, 105, 0xffffff);
            timeout--;
        }
    }

    public String Version()
    {
        return "Version 1.8 for MC b1.6.5";
    }

    public static void performMove(int i, boolean flag, boolean flag1)
    {
        performMove(i, flag, flag1, false);
    }

    public static void performMove(int i, boolean flag, boolean flag1, boolean flag2)
    {
        float f = dodgeUpForce;
        float f1 = dodgeForce;
        if(flag)
        {
            f += 0.4F;
        }
        if(flag1)
        {
            f1 /= 2.0F;
        }
        float f2 = 0.0F;
        float f3 = 0.0F;
        if(flag2)
        {
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindForward.keyCode))
            {
                f2++;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindLeft.keyCode))
            {
                f3--;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindBack.keyCode))
            {
                f2--;
            } else
            if(Keyboard.isKeyDown(mc.gameSettings.keyBindRight.keyCode))
            {
                f3++;
            } else
            {
                return;
            }
            double d = Math.sqrt(theplayer.motionX * theplayer.motionX + theplayer.motionZ * theplayer.motionZ);
            setRelVel(theplayer, f3, 0.0F, f2, (float)d / 2.0F);
            return;
        }
        if(mc.gameSettings.keyBindForward.keyCode == i)
        {
            setRelVel(theplayer, 0.0F, f, 1.0F, f1);
        } else
        if(mc.gameSettings.keyBindLeft.keyCode == i)
        {
            setRelVel(theplayer, -1F, f, 0.0F + fwForce, f1);
        } else
        if(mc.gameSettings.keyBindBack.keyCode == i)
        {
            setRelVel(theplayer, 0.0F, f, -1F, f1);
        } else
        if(mc.gameSettings.keyBindRight.keyCode == i)
        {
            setRelVel(theplayer, 1.0F, f, 0.0F + fwForce, f1);
        } else
        if(mc.gameSettings.keyBindJump.keyCode == i)
        {
            setRelVel(theplayer, f3, doubleJumpForce, f2, 0.0F);
        }
    }

    public static void setRelVel(Entity entity, float f, float f1, float f2, float f3)
    {
        float f4 = 10F;
        float f5 = 0.0F;
        float f6 = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * f4;
        int i = (int)Math.floor((double)(f6 / 360F) + 0.5D);
        f6 = (f6 - (float)i * 360F) + 270F;
        if(f2 <= 0.0F && f2 < 0.0F)
        {
            f6 += 180F;
        }
        if(f > 0.0F)
        {
            f6 += 90F - f2 * 10F;
        } else
        if(f < 0.0F)
        {
            f6 += 270F + f2 * 10F;
        }
        float f7 = MathHelper.cos(-f6 * 0.01745329F - 3.141593F);
        float f8 = MathHelper.sin(-f6 * 0.01745329F - 3.141593F);
        float f9 = -MathHelper.cos(-f5 * 0.01745329F - 0.7853982F);
        float f10 = MathHelper.sin(-f5 * 0.01745329F - 0.7853982F);
        float f11 = f7 * f9;
        float f12 = f10;
        float f13 = f8 * f9;
        if(f == 0.0F && f2 == 0.0F)
        {
            setVel(entity, (float)entity.motionX / 2.0F, f1, (float)entity.motionZ / 2.0F);
        } else
        {
            setVel(entity, f11 * f3 * -1F, f1, f13 * f3);
        }
    }

    public static void setRelVel2(Entity entity, float f, float f1, float f2, float f3)
    {
        float f4 = 10F;
        float f5 = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * f4;
        float f6 = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * f4;
        int i = (int)Math.floor((double)(f6 / 360F) + 0.5D);
        f6 = (f6 - (float)i * 360F) + 270F;
        f5 = (f5 - (float)i * 360F) + 315F;
        if(f2 <= 0.0F && f2 < 0.0F)
        {
            f6 += 180F;
        }
        if(f > 0.0F)
        {
            f6 += 90F - f2 * 10F;
        } else
        if(f < 0.0F)
        {
            f6 += 270F + f2 * 10F;
        }
        float f7 = MathHelper.cos(-f6 * 0.01745329F - 3.141593F);
        float f8 = MathHelper.sin(-f6 * 0.01745329F - 3.141593F);
        float f9 = -MathHelper.cos(-f5 * 0.01745329F - 0.7853982F);
        float f10 = MathHelper.sin(-f5 * 0.01745329F - 0.7853982F);
        float f11 = f7 * f9;
        float f12 = f10;
        float f13 = f8 * f9;
        if(f == 0.0F && f2 == 0.0F)
        {
            setVel(entity, (float)entity.motionX / 2.0F, f1, (float)entity.motionZ / 2.0F);
        } else
        {
            setVel(entity, f11 * f3 * -1F, f12 * (f3 * 5F), f13 * f3);
        }
    }

    public static void setVel(Entity entity, float f, float f1, float f2)
    {
        entity.motionX += f;
        entity.motionY = f1;
        entity.motionZ += f2;
    }

    public static int spriteIndex;
    public static String modName = "MovePlus";
    public static World worldRef;
    public static EntityPlayer theplayer;
    public static Minecraft mc;
    public static int timeout;
    public static String msg;
    public static int color;
    public static int defaultColor = 0xffffff;
    public static int lastKey = 0;
    public static int keys[];
    public static long keyTimes[] = {
        0L, 0L, 0L, 0L, 0L
    };
    public static boolean secondPress[] = {
        false, false, false, false, false
    };
    public static boolean dodged;
    public static boolean doubleJumped;
    public static boolean speedJumped;
    public static long landTime;
    public static boolean lastTickLanded;
    public static long tickCount = 0L;
    public static long timeCount = 0L;
    public static long prevTimeCount = 0L;
    @MLProp
    public static boolean useDoubleJump = true;

    @MLProp
    public static boolean useGroundDodge = true;

    @MLProp
    public static boolean useWallDodge = true;

    @MLProp
    public static boolean useAirDodge = true;

    @MLProp
    public static boolean useBoostDodge = true;

    @MLProp
    public static boolean useSpeedJump = true;

    @MLProp
    public static boolean useAirControl = true;

    @MLProp
    public static float dodgeUpForce = 0.4F;

    @MLProp
    public static float doubleJumpForce = 0.5F;

    @MLProp
    public static float dodgeForce = 1.6F;
    public static float fwForce = 0.8F;

    @MLProp
    public static int dodgeMinDelayTime = 7;
    public static Achievement boostdodged;

    @MLProp
    public static boolean speedMining = false;

    @MLProp
    public static boolean dolphinSkills = false;

    @MLProp
    public static float dolphinSpeed = 0.2F;

    @MLProp
    public static float dolphinSpeedMax = 15.0F;

    @MLProp
    public static float airControlSpeed = 0.1F;

    @MLProp
    public static float airControlSpeedMax = 0.15F;

    @MLProp
    public static float speedJumpMax = 0.9F;
    public static boolean superMagicProperty = true;
    public static boolean ingui = false;

}
